# -*- coding: utf-8 -*-
'''eof
name:申请企业主要股东黑名单校验
code:R65_EntBlackListOfMajorShareholderscheck
tableName:
columnName:
groups:个人及企业黑名单校验
dependencies:WDXT_F_Black,WDXT_F_AmlBlack
type:常用指标
datasourceType:在线指标
description:
eof'''

import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import json

null_type_list = ['',' ',None,'null','NULL','/','-','--']

def checkBlack(base, baseName, blackList):
    if base in null_type_list:
        return u"获取到的数据为空"
    try:
        code = base["sysHead"]["responseCode"]
    except:
        return u"接口获取失败"
    if code == "0":
        try:
            blackInfo = base.get("body").get(baseName)
        except:
            return u"接口获取失败"
        if blackInfo not in null_type_list and isinstance(blackInfo, list):
            if len(blackInfo) >= 1:
                flag = False
                for black in blackInfo:
                    certId = black.get("CERTID")
                    if certId not in null_type_list and certId in blackList:
                        return 0
                    elif certId in null_type_list:
                        flag = True
                if flag:
                    return u"接口数据异常"
                return 1
            else:
                return 1
        else:
            return "接口数据异常"
    elif code == '99':
        return u"缺失值"
    else:
        return u"接口获取失败"

def getRule65():
    id_list = []
    shareHolderList = json.loads(ratingRequest.get("shareHolderList"))
    for i in shareHolderList:
        if i.get('creditCode') not in null_type_list:
            id_list.append(i.get("creditCode"))
    if len(id_list) == 0:
        return 1
    blackResult = checkBlack(WDXT_F_Black, "BLACKLISTDATAS", id_list)
    amlBlackResult = checkBlack(WDXT_F_AmlBlack, "AMLBLACKLISTDATAS", id_list)
    if blackResult == 0 or amlBlackResult == 0:
        return 0
    elif blackResult != 1:
        raise RuntimeError(blackResult)
    elif amlBlackResult != 1:
        raise RuntimeError(amlBlackResult)
    else:
        return 1

result = getRule65()

